//
//  JobInfoViewController.m
//  Liuhe
//
//  Created by zr on 2018/8/8.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "JobInfoViewController.h"

@interface JobInfoViewController ()

@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UILabel * moneyLabel;
@property (nonatomic, weak)UILabel * timeLabel;
@property (nonatomic, weak)UILabel * watchLabel;
@property (nonatomic, strong)UIView * oneLineView;
@property (nonatomic, strong)UIView * twoLineView;
@property (nonatomic, strong)UIView * middleView;
@property (nonatomic, strong)UIView * bottomView;
@property (nonatomic, strong)UILabel * postionLabel;
@property (nonatomic, strong)UILabel * postionValueLabel;
@property (nonatomic, strong)UILabel * requireLabel;
@property (nonatomic, strong)UILabel * requireValueLabel;
@property (nonatomic, strong)UILabel * otherLabel;
@property (nonatomic, strong)UILabel * otherValueLabel;
@property (nonatomic, weak)UILabel * adressLabel;
@property (nonatomic, strong)UILabel * adressValueLabel;
@property (nonatomic, weak)UILabel * exploreJobLabel;
@property (nonatomic, weak)UITextView * textView;
@property (nonatomic, weak)UIView * leftView;
@property (nonatomic, weak)UIView * rightView;
@property (nonatomic, weak)UIView * leftImage;
@property (nonatomic, weak)UIView * rightImage;
@property (nonatomic, weak)UIView * leftLabel;
@property (nonatomic, weak)UIView * rightLabel;

@end

@implementation JobInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = WHITE_COLOR;
    
    [self setupNav];
    [self setupUI];
    
}


- (void)setupNav{
    
    self.title = @"详情";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(0, 0, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"1返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
    
}

- (void)backToView{
    
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)setupUI{
    
    // timeStampString 是服务器返回的13位时间戳
    NSString *timeStampString  = self.model.ctime;
    
    // iOS 生成的时间戳是10位
    NSTimeInterval interval    =[timeStampString doubleValue];
    NSDate *date               = [NSDate dateWithTimeIntervalSince1970:interval];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateString       = [formatter stringFromDate: date];
    //    NSLog(@"服务器返回的时间戳对应的时间是:%@",dateString);
//
//    self.timeLabel.text = dateString;
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = self.model.position;
    titleLabel.textColor = BLACK_COLOR;
    titleLabel.font = [UIFont systemFontOfSize:16 * SCREENH6];
    
    self.titleLabel = titleLabel;
    
    [self.view addSubview:self.titleLabel];
    
    
    UILabel * moneyLabel = [UILabel new];
    
    moneyLabel.text = [NSString stringWithFormat:@"%@ 元/月",self.model.salary];
    moneyLabel.textColor = [UIColor redColor];
    moneyLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    self.moneyLabel = moneyLabel;
    
    [self.view addSubview:self.moneyLabel];
    
    
    UILabel * timeLabel = [UILabel new];
    
    timeLabel.text = [NSString stringWithFormat:@"更新：%@",dateString];;
    timeLabel.textColor = [UIColor grayColor];
    timeLabel.font = [UIFont systemFontOfSize:11 * SCREENH6];
    
    self.timeLabel = timeLabel;
    
    [self.view addSubview:self.timeLabel];
    
    
    UILabel * watchLabel = [UILabel new];
    
    watchLabel.text = @"浏览：180";
    watchLabel.textColor = [UIColor grayColor];
    watchLabel.font = [UIFont systemFontOfSize:11 * SCREENH6];
    
    self.watchLabel = watchLabel;
    
    [self.view addSubview:self.watchLabel];
    
    
    self.oneLineView = [self setupLineView];
    [self.view addSubview:self.oneLineView];
    
    self.twoLineView = [self setupLineView];
    [self.view addSubview:self.twoLineView];
    
    self.middleView = [self setupLineView];
    [self.view addSubview:self.middleView];
    
    self.bottomView = [self setupLineView];
    [self.view addSubview:self.bottomView];
    
    self.postionLabel = [self setupLabelWith:@"one" WithName:@"职位:"];
    [self.view addSubview:self.postionLabel];
    
    self.postionValueLabel = [self setupLabelWith:@"two" WithName:@"销售经理"];
    [self.view addSubview:self.postionValueLabel];
    
    self.requireLabel = [self setupLabelWith:@"one" WithName:@"要求:"];
    [self.view addSubview:self.requireLabel];
    
    self.requireValueLabel = [self setupLabelWith:@"two" WithName:@"招2人/学历不限/经验不限"];
    [self.view addSubview:self.requireValueLabel];
    
    self.otherLabel = [self setupLabelWith:@"one" WithName:@"其他:"];
    [self.view addSubview:self.otherLabel];
    
    self.otherValueLabel = [self setupLabelWith:@"two" WithName:@"周末双休"];
    [self.view addSubview:self.otherValueLabel];
    
    
    UILabel * adressLabel = [UILabel new];
    
    adressLabel.text = @"工作地址";
    adressLabel.textColor = BLACK_COLOR;
    adressLabel.font = [UIFont systemFontOfSize:16 * SCREENH6];
    
    self.adressLabel = adressLabel;
    
    [self.view addSubview:self.adressLabel];
    
    NSString * adress = [NSString stringWithFormat:@"工作地址：%@",self.model.address];
    self.adressValueLabel = [self setupLabelWith:@"two" WithName:adress];
     [self.view addSubview:self.adressValueLabel];
    
    
    UILabel * exploreJobLabel = [UILabel new];
    
    exploreJobLabel.text = @"职位描述";
    exploreJobLabel.textColor = BLACK_COLOR;
    exploreJobLabel.font = [UIFont systemFontOfSize:16 * SCREENH6];
    
    self.exploreJobLabel = exploreJobLabel;
    
    [self.view addSubview:self.exploreJobLabel];
    
    
    UITextView *textView =[[UITextView alloc] init];
    textView.backgroundColor= [UIColor whiteColor];
    textView.text = self.model.describe;
    textView.textColor = [UIColor blackColor];
    textView.editable = NO;
    textView.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    self.textView = textView;
    
    [self.view addSubview:self.textView];
    
    
    UITapGestureRecognizer *tapLeftGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionLeft)];
    UITapGestureRecognizer *tapRightGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionRight)];
    
    UIView * leftView = [UIView new];
    
    leftView.backgroundColor = MAINCOLOR;
    leftView.userInteractionEnabled = YES;
    [leftView addGestureRecognizer:tapLeftGR];
    
    self.leftView = leftView;
    
    [self.view addSubview:self.leftView];
    
    
    UIImageView * leftImage = [UIImageView new];
    
    leftImage.image = ImageNamed(@"xiayige");
    leftImage.userInteractionEnabled = YES;
    
    self.leftImage = leftImage;
    
    [self.leftView addSubview:self.leftImage];
    
    
    UILabel * leftLabel = [UILabel new];
    
    leftLabel.text = @"下一个职位";
    leftLabel.textColor = WHITE_COLOR;
    leftLabel.font = [UIFont systemFontOfSize:16 * SCREENH6];
    leftLabel.userInteractionEnabled = YES;
    
    self.leftLabel = leftLabel;
    
    [self.leftView addSubview:self.leftLabel];
    
    
    UIView * rightView = [UIView new];
    
    rightView.backgroundColor = [UIColor redColor];
    rightView.userInteractionEnabled = YES;
    [rightView addGestureRecognizer:tapRightGR];
    
    self.rightView = rightView;
    
    [self.view addSubview:self.rightView];
    
    
    UIImageView * rightImage = [UIImageView new];
    
    rightImage.image = ImageNamed(@"dianhua");
    rightImage.userInteractionEnabled = YES;
    
    self.rightImage = rightImage;
    
    [self.rightView addSubview:self.rightImage];
    
    
    UILabel * rightLabel = [UILabel new];
    
    rightLabel.text = @"拨打电话";
    rightLabel.textColor = WHITE_COLOR;
    rightLabel.font = [UIFont systemFontOfSize:16 * SCREENH6];
    rightLabel.userInteractionEnabled = YES;
    
    self.rightLabel = rightLabel;
    
    [self.rightView addSubview:self.rightLabel];
}


- (void)viewDidLayoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(20 * SCREENH6);
    }];
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.moneyLabel);
        make.top.mas_equalTo(self.moneyLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.watchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.timeLabel);
        make.leading.mas_equalTo(self.timeLabel.mas_trailing).offset(30 * SCREENH6);
    }];
    
    [self.oneLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.titleLabel);
        make.height.mas_equalTo(1 * SCREENH6);
        make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(25 * SCREENH6);
    }];
    
    [self.postionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.timeLabel);
        make.top.mas_equalTo(self.oneLineView.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.postionValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.postionLabel.mas_trailing).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.postionLabel);
    }];
    
    [self.requireLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.postionLabel);
        make.top.mas_equalTo(self.postionLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.requireValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.requireLabel.mas_trailing).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.requireLabel);
    }];
    
    [self.otherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.requireLabel);
        make.top.mas_equalTo(self.requireLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.otherValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.otherLabel.mas_trailing).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.otherLabel);
    }];
    
    [self.middleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(3 * SCREENH6);
        make.top.mas_equalTo(self.otherLabel.mas_bottom).offset(20);
    }];
    
    [self.adressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.otherLabel);
        make.top.mas_equalTo(self.middleView.mas_bottom).offset(20 * SCREENH6);
    }];
    
    [self.twoLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.oneLineView);
        make.top.mas_equalTo(self.adressLabel.mas_bottom).offset(8 * SCREENH6);
    }];
    
    [self.adressValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.adressLabel);
        make.top.mas_equalTo(self.twoLineView.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.middleView);
        make.top.mas_equalTo(self.adressValueLabel.mas_bottom).offset(20 * SCREENH6);
    }];
    
    [self.exploreJobLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.adressValueLabel);
        make.top.mas_equalTo(self.bottomView.mas_bottom).offset(10 * SCREENH6);
    }];

    
    [self.leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.bottom.mas_equalTo(self.view);
        make.height.mas_equalTo(42 * SCREENH6);
        make.width.mas_equalTo(150 * SCREENH6);
    }];
    
    [self.leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.leftView);
        make.leading.mas_equalTo(self.leftView).offset(19 * SCREENH6);
        make.height.width.mas_equalTo(19 * SCREENH6);
    }];
    
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.leftView);
        make.leading.mas_equalTo(self.leftImage.mas_trailing).offset(4 * SCREENH6);
    }];
    
    [self.rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.bottom.mas_equalTo(self.view);
        make.height.mas_equalTo(self.leftView);
        make.leading.mas_equalTo(self.leftView.mas_trailing);
    }];
    
    [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.rightView);
        make.leading.mas_equalTo(self.rightView).offset(69 * SCREENH6);
        make.height.width.mas_equalTo(18.5 * SCREENH6);
    }];
    
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.rightView);
        make.leading.mas_equalTo(self.rightImage.mas_trailing).offset(4 * SCREENH6);
    }];
    
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.oneLineView);
        make.top.mas_equalTo(self.exploreJobLabel.mas_bottom).offset(10 * SCREENH6);
        make.bottom.mas_equalTo(self.leftView.mas_top).offset(-15 * SCREENH6);
    }];
}


//轻拍手势的回调方法
- (void)tapActionLeft{

        NSLog(@"我轻拍了left gestureView");

}


- (void)tapActionRight{
    
//    NSLog(@"我轻拍了right gestureView");
    
    NSString * tel = [NSString stringWithFormat:@"tel:%@",self.model.mobile];
    
    UIWebView * callWebview = [[UIWebView alloc]init];
    
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tel]]];
    
    [[UIApplication sharedApplication].keyWindow addSubview:callWebview];
}



- (UILabel *)setupLabelWith:(NSString *)type WithName:(NSString *)string{
    
    UILabel * label = [UILabel new];
    
    if ([type isEqualToString:@"one"]) {
        
        label.textColor = [UIColor grayColor];
    }else{
        
        label.textColor = BLACK_COLOR;
    }
    
    label.text = string;
    label.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    return label;
    
}


- (UIView *)setupLineView{
    
    UIView * view = [UIView new];
    
    view.backgroundColor = ColorWithRGB(0xE6E6E6);
    
    return view;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
